<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    if (true) {
        let a= 12;
        // 先声明 再使用
    }
    // console.log(a)
    // 常量
    const  PI = 3.14
    const str = "str"

    const arr = [1,2]
    const obj = {name:"zhangsan"}

    arr[0] = 3
    console.log(arr)
    obj.name = "lisi"

    //数组解构
    let [a,b] = arr
    console.log(a)
    console.log(b)

    // 对象解构
    let  {name:aname} = obj
    console.log(aname)
    // 箭头函数
    function f() {
    }
    const ff = function () {
        console.log(this)
        return ()=>{
            console.log(this)
        }
    };
    const fn =  (num1,num2)=> num1+num2
    const fn1 = num1=> num1*2
    const fnn =  ff.call(obj)
    fnn()

    let ary = [{
        id: 1,
        name: '张三'
    }, {
        id: 2,
        name: "李四"
    }];
    let find = ary.findIndex(item=>item.id===2)
    console.log(find)

    // 模板字符串 反引号 ``
    let bb = "b"
    let aStr = `a${bb}
    a`
    console.log(aStr)

    //定义了父类
    class Father {
        constructor(x, y) {
            this.x = x;
            this.y = y;
        }
        sum() {
            console.log(this.x + this.y);
        }
    }

    class Son extends Father{
        constructor(a,b) {
            super(a,b); // 第一行
            this.a = a
            this.b = b
        }

        subtract(){
            console.log(this.a-this.b)
        }
    }
    var son = new Son(1,2);
    son.sum()
    son.subtract();

    // 立即执行的箭头函数
        (()=>{
            fetch("https://api.apiopen.top/api/getPinYin?text='汉字'").then(resp=>{
                return resp.json()
            }).then(res=>{
                console.log(res)
            })

            fetch('https://api.apiopen.top/api/login', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ account: '309324904@qq.com', password: "123456" })
            }).then(resp=>{
                return resp.json()
            }).then(res=>{
                console.log(res)
            })

        })()
</script>
</html>